#ifndef _BlockManager
#define _BlockManager

#include <time.h>

#include <openssl/bn.h>
#pragma comment (lib, "libeay32.lib")


struct Block {
	BIGNUM *index;
	BIGNUM *count;
	bool complete;
	time_t date_assigned;	// used to determine if its too soon to assign again

	Block *prev, *next;
};

class BlockManager {

public:
	BIGNUM *todo_count;
	BIGNUM *block_size;
	int timeout;
	BIGNUM *index;	// next index to start a new block

	Block *head, *tail;

	// Constructor
	BlockManager();
	// Deconstructor
	~BlockManager();

	// obtain a new block
	Block* get();

	// set a block as complete
	bool set(char* /*index*/);

	// return if all blocks are complete
	bool isComplete();

	// returns the number of todos completed (slower than isComplete)
	char* getStatus();

	// initialize block manager with new block info
	void init(char* /*todo_count*/, char* /*block_size*/, int /*timeout*/);

	// clear out the current blocks
	void clear();
};

#endif // _BlockManager